home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte19 / putdest.c < prev    next >
C/C++ Source or Header  |  1996-04-29  |  8KB  |  274 lines

  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include "PutDest.h"
  5. #include <vfw.h>
  6.  
  7.  
  8. #if defined (WIN32)
  9.     #define IS_WIN32 TRUE
  10. #else
  11.     #define IS_WIN32 FALSE
  12. #endif
  13.  
  14. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  15. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  16. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  17.  
  18.  
  19. HINSTANCE hInst;   // current instance
  20.  
  21. LPCTSTR lpszAppName = "MyApp";
  22. LPCTSTR lpszTitle   = "My Application"; 
  23.  
  24. // the rest of the stuff
  25. //......................
  26.  
  27. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  28.  
  29.  
  30. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  31.                       LPTSTR lpCmdLine, int nCmdShow)
  32. {
  33.    MSG      msg;
  34.    HWND     hWnd; 
  35.    WNDCLASS wc;
  36.  
  37.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  38.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  39.    wc.cbClsExtra    = 0;                      
  40.    wc.cbWndExtra    = 0;                      
  41.    wc.hInstance     = hInstance;              
  42.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  43.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  44.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  45.    wc.lpszMenuName  = lpszAppName;              
  46.    wc.lpszClassName = lpszAppName;              
  47.  
  48.    if ( IS_WIN95 )
  49.    {
  50.       if ( !RegisterWin95( &wc ) )
  51.          return( FALSE );
  52.    }
  53.    else if ( !RegisterClass( &wc ) )
  54.       return( FALSE );
  55.  
  56.    hInst = hInstance; 
  57.  
  58.    hWnd = CreateWindow( lpszAppName, 
  59.                         lpszTitle,    
  60.                         WS_OVERLAPPEDWINDOW, 
  61.                         CW_USEDEFAULT, 0, 
  62.                         CW_USEDEFAULT, 0,  
  63.                         NULL,              
  64.                         NULL,              
  65.                         hInstance,         
  66.                         NULL               
  67.                       );
  68.  
  69.    if ( !hWnd ) 
  70.       return( FALSE );
  71.  
  72.    ShowWindow( hWnd, nCmdShow ); 
  73.    UpdateWindow( hWnd );         
  74.  
  75.    while( GetMessage( &msg, NULL, 0, 0) )   
  76.    {
  77.       TranslateMessage( &msg ); 
  78.       DispatchMessage( &msg );  
  79.    }
  80.  
  81.    return( msg.wParam ); 
  82. }
  83.  
  84.  
  85. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  86. {
  87.     WNDCLASSEX wcex;
  88.  
  89.    wcex.style         = lpwc->style;
  90.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  91.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  92.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  93.    wcex.hInstance     = lpwc->hInstance;
  94.    wcex.hIcon         = lpwc->hIcon;
  95.    wcex.hCursor       = lpwc->hCursor;
  96.    wcex.hbrBackground = lpwc->hbrBackground;
  97.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  98.    wcex.lpszClassName = lpwc->lpszClassName;
  99.  
  100.    // Added elements for Windows 95.
  101.    //...............................
  102.    wcex.cbSize = sizeof(WNDCLASSEX);
  103.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  104.                             IMAGE_ICON, 16, 16,
  105.                             LR_DEFAULTCOLOR );
  106.             
  107.    return RegisterClassEx( &wcex );
  108. }
  109.  
  110. HWND hMCIWnd = NULL;   // MCIWnd window handle
  111. RECT rSource, rCurr, rDest;
  112.  
  113.  
  114. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  115. {
  116.    switch( uMsg )
  117.    {
  118.       case WM_CREATE :
  119.               // create MCIWnd window
  120.               //.....................
  121.  
  122.               hMCIWnd = MCIWndCreate(hWnd, hInst, 
  123.                                      WS_VISIBLE | 
  124.                                      WS_CHILD, 
  125.                                      NULL
  126.                                     );
  127.                           
  128.               if (hMCIWnd)
  129.               {
  130.                   MCIWndOpen(hMCIWnd, "Sample.avi", 0);
  131.                   MCIWndPlay(hMCIWnd);
  132.               }
  133.               else
  134.               {
  135.                   MessageBox(hWnd, "Error creating MCIWnd window...", 
  136.                              NULL, MB_OK);
  137.                   DestroyWindow( hWnd );
  138.               }
  139.               break;
  140.  
  141.       case WM_COMMAND :
  142.               switch( LOWORD( wParam ) )
  143.               {  
  144.                  case IDM_NORMAL:
  145.                          MCIWndGetSource(hMCIWnd, &rSource);
  146.                          MCIWndPutDest(hMCIWnd, &rSource);
  147.                          break;
  148.  
  149.                  case IDM_STRETCH_IMAGE:
  150.                          MCIWndGetDest(hMCIWnd, &rCurr);
  151.                          
  152.                          rDest.top    = rCurr.top;
  153.                          rDest.right  = rCurr.right; 
  154.                          rDest.left   = rCurr.left + 
  155.                                         ((rCurr.left - rCurr.right) * 2);
  156.                          rDest.bottom = rCurr.bottom + 
  157.                                         ((rCurr.bottom - rCurr.top) * 2); 
  158.                          
  159.                          MCIWndPutDest(hMCIWnd, &rDest);
  160.                          break;
  161.                          
  162.                  case IDM_STRINK_IMAGE:
  163.                          MCIWndGetDest(hMCIWnd, &rCurr);
  164.                          
  165.                          rDest.top    = rCurr.top;
  166.                          rDest.right  = rCurr.right;
  167.                          rDest.left   = rCurr.left - 
  168.                                         ((rCurr.left - rCurr.right) / 2); 
  169.                          rDest.bottom = rCurr.bottom - 
  170.                                         ((rCurr.bottom - rCurr.top) / 2); 
  171.                          
  172.                          MCIWndPutDest(hMCIWnd, &rDest);
  173.                          break;         
  174.                  
  175.                  case IDM_MOVE_DOWN:
  176.                          MCIWndGetDest(hMCIWnd, &rCurr);
  177.  
  178.                          rCurr.top    -= 100;
  179.                          rCurr.bottom -= 100;
  180.                          
  181.                          MCIWndPutDest(hMCIWnd, &rCurr);
  182.                          break; 
  183.                  
  184.                  case IDM_MOVE_UP:
  185.                          MCIWndGetDest(hMCIWnd, &rCurr);
  186.                          
  187.                          rCurr.top    += 100;
  188.                          rCurr.bottom += 100;
  189.                          
  190.                          MCIWndPutDest(hMCIWnd, &rCurr);
  191.                          break; 
  192.                  
  193.                  case IDM_MOVE_LEFT:
  194.                          MCIWndGetDest(hMCIWnd, &rCurr);
  195.                          
  196.                          rCurr.right += 100;
  197.                          rCurr.left  += 100; 
  198.                          
  199.                          MCIWndPutDest(hMCIWnd, &rCurr);
  200.                          break; 
  201.                  
  202.                  case  IDM_MOVE_RIGHT:
  203.                          MCIWndGetDest(hMCIWnd, &rCurr);
  204.  
  205.                          rCurr.right -= 100;
  206.                          rCurr.left  -= 100; 
  207.                          
  208.                          MCIWndPutDest(hMCIWnd, &rCurr);
  209.                          break;
  210.  
  211.                  // other commands
  212.                  //...............
  213.                  
  214.                  case IDM_ABOUT :
  215.                         DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  216.                         break;
  217.  
  218.                  case IDM_EXIT :
  219.                         DestroyWindow(hWnd);
  220.                         break;
  221.               }
  222.               break;
  223.  
  224.       case WM_DESTROY :
  225.               // destroy MCIWnd, if one exists
  226.               //..............................
  227.  
  228.               if (hMCIWnd)
  229.                   MCIWndDestroy(hMCIWnd);
  230.  
  231.               PostQuitMessage(0);
  232.               break;
  233.  
  234.       default :
  235.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  236.    }
  237.  
  238.    return( 0L );               
  239. }
  240.  
  241.  
  242. LRESULT CALLBACK About( HWND hDlg,           
  243.                         UINT message,        
  244.                         WPARAM wParam,       
  245.                         LPARAM lParam)
  246. {
  247.    switch (message) 
  248.    {
  249.        case WM_INITDIALOG: 
  250.                return (TRUE);
  251.  
  252.        case WM_COMMAND:                              
  253.                if (   LOWORD(wParam) == IDOK         
  254.                    || LOWORD(wParam) == IDCANCEL)    
  255.                {
  256.                        EndDialog(hDlg, TRUE);        
  257.                        return (TRUE);
  258.                }
  259.                break;
  260.    }
  261.  
  262.    return (FALSE); 
  263. }
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.